<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--{include file='comm/header.tpl'}-->
    <title>添加资源位</title>
    <!--{include file='comm/comm_editor.tpl'}-->
    <!--{include file='comm/comm_pic.tpl'}-->
</head>
<body>
<div style="width:100%">

    <div class="items clearfix">
        <h2 style="" class="tal">正在操作：添加图片资源位</h2>
        <div class="items2">

            <!--{if !$source_category_array}-->

                <div class="error-box">
                    <!--{$error_msg}-->
                </div>

            <!--{else}-->

                <div class="select-box">
                    <div onclick="source.change(4);">商品资源位</div>
                    <div class="selected" onclick="source.change(5);">图片资源位</div>
                </div>

                <div>
                    <form id="source_form" onsubmit="return false;">
                        <table>
                            <tbody>
                            <tr>
                                <td class="tar" width="150">资源位分类：</td>
                                <td width="500">
                                    <select id="parnet_id" name="parnet_id">
                                        <!--{foreach from=$source_category_array item=source}-->
                                            <!--{if $source->parent_category_id == 0}-->
                                                <option value="<!--{$source->source_category_id}-->" disabled="disabled"><!--{$source->source_category_title}--></option>
                                            <!--{else}-->
                                                <option value="<!--{$source->source_category_id}-->">&nbsp;&nbsp;<!--{$source->source_category_title}--></option>
                                            <!--{/if}-->
                                        <!--{/foreach}-->
                                    </select>
                                    <font color="red">*</font>
                                </td>
                                <td width="*" rowspan="5">
                                    <div id="show_img" style="border: 1px solid #CCCCCC;height: 185px;margin: 0 auto;width: 185px;"></div>
                                    <input type="hidden" name="promotion_img" id="promotion_img" value="" />
                                </td>
                            </tr>
                            <tr>
                                <td class="tar">资源位标题：</td>
                                <td>
                                    <input type="text" value="" name="title" id="title" style="width: 400px;" />
                                    <font class="red">*</font>
                                </td>
                            </tr>
                            <tr>
                                <td class="tar">资源位简述：</td>
                                <td>
                                    <input type="text" value="" name="brief" id="brief" style="width: 400px;" />
                                </td>
                            </tr>
                            <tr>
                                <td class="tar">资源位URL：</td>
                                <td>
                                    <input type="text" value="" name="url" id="url" style="width: 400px;" />
                                </td>
                            </tr>
                            <tr>
                                <td class="tar">使用标志：</td>
                                <td>
                                    <input type="radio" value="1" name="useFlg" checked="checked" /> 启用
                                    <input type="radio" value="0" name="useFlg" /> 禁用
                                    <font color="red">*</font>
                                </td>
                            </tr>
                            <tr>
                                <td class="tar">是否打开新页面：</td>
                                <td>
                                    <input type="radio" value="1" name="openPage" checked="checked" /> 是
                                    <input type="radio" value="0" name="openPage" /> 否
                                    <font color="red">*</font>
                                    <input type="hidden" name="id" value="0" />
                                </td>
                                <td class="tac">
                                    <input type="button" value="上传图片" class="btn" onclick="source.uploadImg();" />
                                </td>
                            </tr>
                            </tbody>
                        </table>
                        <div>
                            <textarea name="description" id="description" style="width:100%;height:400px;visibility:hidden;"></textarea>
                        </div>
                    </form>
                </div>

            <!--{/if}-->

        </div>
    </div>


    <div class="bottom_fixbox">
        <div class="rectbox tac">
            <input type="button" class="btn" onclick="source.check();" value="添加资源位分类" />&nbsp;&nbsp;&nbsp;
            <input type="button" class="btn" onclick="E.closeWindows();" value="关闭" />
        </div>
    </div>

</div>

<script type="text/javascript">

    var source = {

        category_id: <!--{$category_id|default:0}-->,

        //检查数据
        check: function() {
            editor.sync();
            this.dt = E.getFormValues("source_form");
            var error_msg = "";
            if (this.dt.title == "")
                error_msg += "资源位标题不能为空<br />";
            if (this.dt.url == "" && this.dt.content == "")
                error_msg += "资源位URL和资源位内容不能同时为空<br />";
            if (error_msg != "")
                E.alert(error_msg);
            else
                E.confirm("您确认要添加资源位信息吗？", "source.add");
        },

        //保存资源位信息
        add: function() {
            $.ajax({
                type: "POST",
                url: "/invokingAjax-backend/content/source.ajax?operFlg=4",
                dataType: "JSON",
                data: this.dt,
                success: function( result_obj ) {
                    if (result_obj.code == 200) {
                        if (source.category_id == 0)
                            E.opener("source.load");
                        E.alert(result_obj.message, 2, "E.closeWindows");
                    } else {
                        E.alert(result_obj.message);
                    }
                }
            });
        },

        //上传图片
        uploadImg: function() {
            E.open("/quanliadmin/app/uploads/imageUpload.php?uploadPara=16", "上传", {height: 50, width: 600, top: 280, left: 300});
        },

        //切换标签
        change: function(operFlg) {
            if (this.category_id) {
                self.location = "/quanliadmin/app/content/source.pscript?operFlg=" + operFlg + "&category_id=" + this.category_id;
            } else {
                self.location = "/quanliadmin/app/content/source.pscript?operFlg=" + operFlg;
            }
        }

    };

    function getUploadFileName(upload_fileName) {
        var list_html = "<a class=\"fancybox\" href=\"/quanliadmin/docroot/images/promotion/" + upload_fileName + "\"><img height=\"185px\" width=\"185px\" src=\"/quanliadmin/docroot/images/promotion/" + upload_fileName + "\"></a>";
        $("#show_img").html(list_html);
        $("#promotion_img").val(upload_fileName);
    }

    $(document).ready(function() {
        $('.fancybox').fancybox();
    });


</script>

</body>

</html>
